package com.yljk.homedoctor.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yilijk.base.utils.ALog;
import com.yljk.homedoctor.R;
import com.yljk.homedoctor.model.entity.MyRoonEntity;

import java.util.List;

public class MyRoomAdapter extends BaseMultiItemQuickAdapter<MyRoonEntity, BaseViewHolder> {


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public MyRoomAdapter(List<MyRoonEntity> data) {
        super(data);
        addItemType(0,R.layout.my_room_item);
        addItemType(1,R.layout.my_room_item1);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyRoonEntity item) {
        //item name
        helper.setText(R.id.my_room_name,item.getName());
        //item isHas funtion
        helper.setText(R.id.my_room_count,item.getUnReadCount() > 99 ? "99+" : item.getUnReadCount() + "");
        ALog.i(TAG, "convert: "+item.getUnReadCount()+"————"+item.getName());
        if (item.isHasFunction()){
            Glide.with(mContext).load(item.getSelectIcon()).into((ImageView) helper.getView(R.id.my_room_img));
            helper.setAlpha(R.id.my_room_name,1.0f);
            if (item.getUnReadCount()>0){
                helper.setVisible(R.id.my_room_count,true);
            }else{
                helper.setVisible(R.id.my_room_count,false);
            }
        }else{
            helper.setVisible(R.id.my_room_count,false);
            helper.setAlpha(R.id.my_room_name,0.5f);
            Glide.with(mContext).load(item.getUnselectIcon()).into((ImageView) helper.getView(R.id.my_room_img));
        }

        switch (helper.getItemViewType()){
            case 0:
//                helper.setText(R.id.my_room_count,item.getUnReadCount()+"");
                ALog.e(TAG, "convert: "+helper.getItemViewType() );
                break;
            case 1:
                helper.setVisible(R.id.my_room_count,true);
                ALog.e(TAG, "convert: "+helper.getItemViewType() );
                if (TextUtils.isEmpty(item.getUnReadCountDesc())){
                    helper.setVisible(R.id.my_room_count,false);
                }else{
                    helper.setVisible(R.id.my_room_count,true);
                    helper.setText(R.id.my_room_count,item.getUnReadCountDesc());
                }
                break;
        }
    }
}
